package com.privacy.accountmgr.utils

import android.content.Context
import android.content.SharedPreferences

object PreferenceHelper {
    val IS_AGREED_TERMS = "is_agreed_terms"

    fun getSharedPreference(context: Context): SharedPreferences {
        return context.getSharedPreferences("booster_sp", Context.MODE_PRIVATE)
    }

    fun getString(key: String, defValue: String): String? {
        return getSharedPreference(GlobalContext.context!!).getString(key, defValue)
    }

    fun getInt(key: String, defValue: Int): Int {
        return getSharedPreference(GlobalContext.context!!).getInt(key, defValue)
    }

    fun getLong(key: String, defValue: Long): Long {
        return getSharedPreference(GlobalContext.context!!).getLong(key, defValue)
    }

    fun getBoolean(key: String, defValue: Boolean): Boolean {
        return getSharedPreference(GlobalContext.context!!).getBoolean(key, defValue)
    }

    fun getFloat(key: String, defValue: Float): Float {
        return getSharedPreference(GlobalContext.context!!).getFloat(key, defValue)
    }

    fun setString(key: String, value: String) {
        getSharedPreference(GlobalContext.context!!).edit().putString(key, value).apply()
    }

    fun setInt(key: String, value: Int) {
        getSharedPreference(GlobalContext.context!!).edit().putInt(key, value).apply()
    }

    fun setLong(key: String, value: Long) {
        getSharedPreference(GlobalContext.context!!).edit().putLong(key, value).apply()
    }

    fun setFloat(key: String, value: Float) {
        getSharedPreference(GlobalContext.context!!).edit().putFloat(key, value).apply()
    }

    fun setBoolean(key: String, value: Boolean) {
        getSharedPreference(GlobalContext.context!!).edit().putBoolean(key, value).apply()
    }

    fun getString(context: Context, key: String, defValue: String): String? {
        return getSharedPreference(context).getString(key, defValue)
    }

    fun getInt(context: Context, key: String, defValue: Int): Int {
        return getSharedPreference(context).getInt(key, defValue)
    }

    fun getLong(context: Context, key: String, defValue: Long): Long {
        return getSharedPreference(context).getLong(key, defValue)
    }

    fun getBoolean(context: Context, key: String, defValue: Boolean): Boolean {
        return getSharedPreference(context).getBoolean(key, defValue)
    }

    fun getFloat(context: Context, key: String, defValue: Float): Float {
        return getSharedPreference(context).getFloat(key, defValue)
    }

    fun setString(context: Context, key: String, value: String) {
        getSharedPreference(context).edit().putString(key, value).apply()
    }

    fun setInt(context: Context, key: String, value: Int) {
        getSharedPreference(context).edit().putInt(key, value).apply()
    }

    fun setLong(context: Context, key: String, value: Long) {
        getSharedPreference(context).edit().putLong(key, value).apply()
    }

    fun setFloat(context: Context, key: String, value: Float) {
        getSharedPreference(context).edit().putFloat(key, value).apply()
    }

    fun setBoolean(context: Context, key: String, value: Boolean) {
        getSharedPreference(context).edit().putBoolean(key, value).apply()
    }
}